package cz.proks.bank;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cz.proks.bank.manager.BankManager;

@Component
public class BankListener {
	private final Logger log = Logger.getLogger(getClass());	
		
	@Autowired
	private BankManager bankManager;
	
	@PreDestroy
	public void contextDestroyed() {
		log.info("Closing bank application");
		
		log.info("Bank application closed");
	}

	@PostConstruct
	public void start() {
		log.info("Initializing bank application");		
				
		try {
			bankManager.registerBank(BankConstants.BANK_CODE, BankConstants.BANK_NAME);
		} catch (Exception e) {
			log.error("Bank application initialization failed!", e);
		}
			
		log.info("Bank application initialized");
	}	
}
